/**
 * Copyright 2009-2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。

 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 */
package chunmap.app.tools.navigate;

import java.awt.AWTEvent;
import java.awt.event.MouseWheelEvent;

import chunmap.app.bench.AbstractTool;
import chunmap.app.bench.EventType;
import chunmap.app.command.ZoomCommand;
/**
 * @author chunquedong
 * 
 */
public class ZoomTool extends AbstractTool {

	@Override
	public boolean actionEvent(AWTEvent event, EventType type) {

		if (event instanceof MouseWheelEvent) {
			MouseWheelEvent e = (MouseWheelEvent) event;

			if (MouseWheelEvent.MOUSE_WHEEL != e.getID())
				return true;

			mouseWheelMoved(e);
		}
		
		return true;
	}


	public void mouseWheelMoved(MouseWheelEvent e) {
//		Point p = new Coordinate2D(e.getX(), e.getY());
//
//		double s = -e.getWheelRotation() / 3d + 1;
//		ZoomCommand cmd=new ZoomCommand(map,s,p);
//		map.executeCommand(cmd);
//		Log.log(Logger.Debug, "zoom finish");
//		map.refreshMap();
		double x = map.getView().x2World(e.getX());
        double y = map.getView().y2World(e.getY());

        if (e.getWheelRotation()== 0) return;

        double s = (e.getWheelRotation() < 0) ? 2 : 0.5;

        ZoomCommand cmd = new ZoomCommand(map, s, x, y);
        map.executeCommand(cmd);
        map.refreshMap();
	}
}
